﻿using DFGK.Service.BBS;
using DFGK_WMS.Model;
using DFGK_WMS.Model.Dto;
using DFGK_WMS.Model.Models;
using DFGK_WMS.Model.Models.LyModel;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using NPOI.POIFS.Crypt.Dsig;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.Drawing;
using System.Security.Claims;

namespace DFGK_WMS.WebAPI
{
    /// <summary>
    /// 父级控制器
    /// </summary>
    public class BaseController : ControllerBase
    {
        private readonly IWebHostEnvironment environment;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="environment"></param>
        public BaseController(IWebHostEnvironment environment)
        {
            this.environment = environment;
        }

        /// <summary>
        /// 获取当前登录人Id
        /// </summary>
        /// <returns></returns>
        protected internal long BaseGetNowUserId()
        {
            string nowuserid = HttpContext.User.FindFirstValue("Id");
            return Convert.ToInt64(nowuserid);
        }

        /// <summary>
        /// 获取当前登录人姓名
        /// </summary>
        /// <returns></returns>
        protected internal string BaseGetNowUserName()
        {
            return HttpContext.User.FindFirstValue("UserName");
        }

        /// <summary>
        /// 获取当前登录人真实姓名
        /// </summary>
        /// <returns></returns>
        protected internal string BaseGetNowUserRealName()
        {
            return HttpContext.User.FindFirstValue("RealName");
        }

        /// <summary>
        /// 获取请求IP
        /// </summary>
        /// <returns></returns>
        protected internal string BaseGetRequestIp()
        {
            var remoteIpAddress = HttpContext.Connection.RemoteIpAddress;
            if (remoteIpAddress != null)
                return remoteIpAddress.ToString();
            return "UNKNOWN";
        }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        protected internal async Task<IActionResult> BaseUploadFile(IFormFile file)
        {
            // 检查文件是否为空
            if (file == null || file.Length == 0)
            {
                return BadRequest("没有选择文件或文件为空.");
            }
            // 检查文件类型
            string fileExtension = Path.GetExtension(file.FileName).ToLower();
            //if (fileExtension != ".jpg" && fileExtension != ".png" && fileExtension != ".gif" && fileExtension != ".jfif")
            //{
            //    return BadRequest("只允许上传 .jpg, .png 和 .gif 和.jfif 格式的文件.");
            //}
            // 检查文件大小
            //if (file.Length > 200 * 1024) // 单位为字节
            //{
            //    return BadRequest("上传的图片必须小于 200KB.");
            //}
            try
            {
                // 获取保存文件的根路径
                string uploadsFolder = Path.Combine(environment.WebRootPath, "file");

                // 创建文件夹（如果不存在）
                Directory.CreateDirectory(uploadsFolder);

                // 创建以当前日期命名的文件夹
                string currentDateFolder = DateTime.Now.ToString("yyyyMMdd");
                string folderPath = Path.Combine(uploadsFolder, currentDateFolder);
                Directory.CreateDirectory(folderPath);

                // 生成以当前时间命名的文件名
                string currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                string fileExtension1 = Path.GetExtension(file.FileName).ToLower();
                string fileName = $"{currentTime}{fileExtension1}";

                // 保存文件到指定路径
                string filePath = Path.Combine(folderPath, fileName);
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                return Ok("http://192.168.1.97:5043/file/" + currentDateFolder + "/" + fileName);
            }
            catch (Exception ex)
            {
                return StatusCode(500, $"文件上传失败：{ex.Message}");
            }
        }

        /// <summary>
        /// Excel导出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult BaseDowLoadExcel<T>(List<T> list)
        {
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(list);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// Excel导出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult InvDown(List<DefectiveProductsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "物料名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "物料编码";   // 修改列名
                worksheet.Cells[1, 3].Value = "仓位编码"; // 修改列名
                worksheet.Cells[1, 4].Value = "库存数量"; // 修改列名
                worksheet.Cells[1, 5].Value = "最近使用状态"; // 修改列名
                worksheet.Cells[1, 6].Value = "最近使用数量"; // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].MaterialName;
                    worksheet.Cells[i + 2, 2].Value = list[i].MaterialCode;
                    worksheet.Cells[i + 2, 3].Value = list[i].CellCode;
                    worksheet.Cells[i + 2, 4].Value = list[i].Qty;
                    if (list[i].SourceType == 1)
                    {
                        worksheet.Cells[i + 2, 5].Value = "入库";
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 5].Value = "其他";
                    }
                    worksheet.Cells[i + 2, 6].Value = list[i].UpdQty;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        #region 报废报损导出
        protected internal IActionResult InvDownScrapLossOrder(List<ScrapLossOrder> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "盘点员姓名";
                worksheet.Cells[1, 2].Value = "设备名称";
                worksheet.Cells[1, 3].Value = "报废/报损类型";
                worksheet.Cells[1, 4].Value = "报废报损数量";
                worksheet.Cells[1, 5].Value = "报废报损金额";
                worksheet.Cells[1, 6].Value = "报废报损日期";
                worksheet.Cells[1, 7].Value = "设备所属部门";
                worksheet.Cells[1, 8].Value = "是否已审批";

                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 8])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].OperatorName;
                    worksheet.Cells[i + 2, 2].Value = list[i].EquipmentName;
                    worksheet.Cells[i + 2, 3].Value = list[i].ScrapLossType;
                    worksheet.Cells[i + 2, 4].Value = list[i].ScrapLossAmount;
                    worksheet.Cells[i + 2, 5].Value = list[i].ScrapLossValue;
                    worksheet.Cells[i + 2, 6].Value = list[i].ScrapLossDate.ToString("yyyy-MM-dd");// 格式化日期

                    worksheet.Cells[i + 2, 7].Value = list[i].Department;

                    // 审批状态列
                    worksheet.Cells[i + 2, 8].Value = list[i].Approved ? "已审批" : "未审批";
                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 8; // 最后一列的列号（这里是8）

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion


        #region 装备数量占比统计
        protected internal IActionResult InvDownEquipment(List<EquipmentSummaryDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "装备名称";
                worksheet.Cells[1, 2].Value = "装备类别";
                worksheet.Cells[1, 3].Value = "装备数量";
                worksheet.Cells[1, 4].Value = "装备占比";
 


                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 4])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Category;
                    worksheet.Cells[i + 2, 2].Value = list[i].EquipmentName;
                    worksheet.Cells[i + 2, 3].Value = list[i].TotalQuantity;
                    worksheet.Cells[i + 2, 4].Value = list[i].EquipmentPercentage;
                   


                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 4; // 最后一列的列号（这里是8）

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        #endregion

        
        #region  装备数量增减统计导出
        protected internal IActionResult InvDownEquipmentChangeStatistics(List<EquipmentChangeDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "装备名称";
                worksheet.Cells[1, 2].Value = "类型";
                worksheet.Cells[1, 3].Value = "时间";
                worksheet.Cells[1, 4].Value = "总数";



                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 4])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].EquipmentName;
                    worksheet.Cells[i + 2, 2].Value = list[i].EquipmentType;
                    worksheet.Cells[i + 2, 3].Value = list[i].ChangeDate.ToString("yyyy-MM-dd");
                    worksheet.Cells[i + 2, 4].Value = list[i].TotalChange;



                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 4; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

        #region  装备组织单位统计导出
        protected internal IActionResult InvDownUnitEquipments(List<UnitEquipmentsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "组织单位名称";
                worksheet.Cells[1, 2].Value = "总数";
                worksheet.Cells[1, 3].Value = "占比";
             



                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 3])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].UnitName;
                    worksheet.Cells[i + 2, 2].Value = list[i].TotalQuantity;
                    worksheet.Cells[i + 2, 3].Value = list[i].EquipmentPercentage;



                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 3; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

        

        #region  装备大数据统计分析导出
        protected internal IActionResult InvDownEquipmentStatistics(List<EquipmentStatisticsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "装备类型";
                worksheet.Cells[1, 2].Value = "总数";
          




                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 2])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Category;
                    worksheet.Cells[i + 2, 2].Value = list[i].TotalQuantity;
                    



                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 2; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

        #region  车辆数量占比统计导出
        protected internal IActionResult InvDownVehicleCategoryStats(List<VehicleCategoryStatsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "类别名称";
                worksheet.Cells[1, 2].Value = "类别的总数量";
                worksheet.Cells[1, 3].Value = "占比数";





                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 3])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Category;
                    worksheet.Cells[i + 2, 2].Value = list[i].TotalQuantity;
                    worksheet.Cells[i + 2, 3].Value = list[i].Percentage;




                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 3; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion


        #region  车辆质量状态统计分析导出
        protected internal IActionResult InvDownVehicleStatusStats(List<VehicleStatusDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "状态";
                worksheet.Cells[1, 2].Value = "数量";
            





                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 2])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Status;
                    worksheet.Cells[i + 2, 2].Value = list[i].Quantity;

                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 2; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

        

        #region  车辆按组织单位统计导出
        protected internal IActionResult InvDownVehicleOrganizationStats(List<VehicleOrganizationStatsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "单位";
                worksheet.Cells[1, 2].Value = "车辆信息";
                worksheet.Cells[1, 3].Value = "车辆数量";
                worksheet.Cells[1, 4].Value = "车辆占比";






                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 4])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Organization;
                    worksheet.Cells[i + 2, 2].Value = list[i].VehicleCategory;
                    worksheet.Cells[i + 2, 3].Value = list[i].TotalQuantity;
                    worksheet.Cells[i + 2, 4].Value = list[i].Percentage;

                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 4; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        #region  车辆采购数据统计分析导出
        protected internal IActionResult InvDownVehiclePurchaseStats(List<VehiclePurchaseStatsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "车辆名称";
                worksheet.Cells[1, 2].Value = "采购日期";
                worksheet.Cells[1, 3].Value = "采购数量";
                worksheet.Cells[1, 4].Value = "总成本";






                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 4])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Name;
                    worksheet.Cells[i + 2, 2].Value = list[i].PurchaseDate;
                    worksheet.Cells[i + 2, 3].Value = list[i].Quantity;
                    worksheet.Cells[i + 2, 4].Value = list[i].TotalCost;

                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 4; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

        #region  组织单位地图定位统计展示导出
        protected internal IActionResult InvDownOrganizationAndStatisticsByRegion(List<OrganizationAndStatisticsDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;
            var memoryStream = new MemoryStream();
            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "组织名";
                worksheet.Cells[1, 2].Value = "组织单位的纬度";
                worksheet.Cells[1, 3].Value = "组织单位的经度";
                worksheet.Cells[1, 4].Value = "组织单位的地址";
                worksheet.Cells[1, 5].Value = "地区名";
                worksheet.Cells[1, 6].Value = "总计数量";
                worksheet.Cells[1, 7].Value = "日期";

                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 7])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                int row = 2; // 从第二行开始填充数据
                foreach (var dto in list)
                {
                    // 遍历 "Organizations" 集合
                    foreach (var organization in dto.Organizations)
                    {
                        worksheet.Cells[row, 1].Value = organization.Name;
                        worksheet.Cells[row, 2].Value = organization.Latitude;
                        worksheet.Cells[row, 3].Value = organization.Longitude;
                        worksheet.Cells[row, 4].Value = organization.Address;

                        // 查找匹配的统计信息
                        var statistics = dto.Statistics.FirstOrDefault(s =>
                            organization.Address.Contains(s.RegionName) // 部分匹配组织地址中的地区
                        );

                        // 如果找到了对应的统计信息
                        if (statistics != null)
                        {
                            worksheet.Cells[row, 5].Value = statistics.RegionName;
                            worksheet.Cells[row, 6].Value = statistics.TotalCount;
                            worksheet.Cells[row, 7].Value = statistics.Datee.ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            worksheet.Cells[row, 5].Value = ""; // 地区名为空
                            worksheet.Cells[row, 6].Value = ""; // 总计数量为空
                            worksheet.Cells[row, 7].Value = ""; // 日期为空
                        }

                        row++; // 移动到下一行
                    }
                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = row - 1;
                var lastColumn = 7; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        #endregion


        #region  库房装备数量统计分析导出
        protected internal IActionResult InvDownEquipmentAnalysis(List<EquipmentAnalysisDto> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "名称";
                worksheet.Cells[1, 2].Value = "类别";
                worksheet.Cells[1, 3].Value = "数量";
                worksheet.Cells[1, 4].Value = "占比";
                worksheet.Cells[1, 5].Value = "时间";






                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 5])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].EquipmentName;
                    worksheet.Cells[i + 2, 2].Value = list[i].EquipmentCategory;
                    worksheet.Cells[i + 2, 3].Value = list[i].TotalQuantity;
                    worksheet.Cells[i + 2, 4].Value = list[i].Percentage;
                    worksheet.Cells[i + 2, 5].Value = list[i].StatisticsDate;

                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 5; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion



        #region  采购标准制定管理导出
        protected internal IActionResult InvDownPurchaseStandardPageData(List<PurchaseStandard> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "采购标准名称";
                worksheet.Cells[1, 2].Value = "适用人员数量";
                worksheet.Cells[1, 3].Value = "标准描述";
                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 3])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].StandardName;
                    worksheet.Cells[i + 2, 2].Value = list[i].EmployeeCount;
                    worksheet.Cells[i + 2, 3].Value = list[i].Description;


                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 3; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion



        #region  报表管理导出
        protected internal IActionResult InvDownQuoteData(List<Quote> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "产品名称";
                worksheet.Cells[1, 2].Value = "报价价格";
                worksheet.Cells[1, 3].Value = "供应商";
                worksheet.Cells[1, 4].Value = "报价日期";
                worksheet.Cells[1, 5].Value = "描述";
                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 5])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].ProductName;
                    worksheet.Cells[i + 2, 2].Value = list[i].Price;
                    worksheet.Cells[i + 2, 3].Value = list[i].Supplier;
                    worksheet.Cells[i + 2, 4].Value = list[i].QuoteDate;
                    worksheet.Cells[i + 2, 5].Value = list[i].Description;



                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 5; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion



        /// <summary>
        /// 供应商导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult SuppliersDown(List<SuppliersDown> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "供应商编码";  // 修改列名
                worksheet.Cells[1, 2].Value = "供应商名称";   // 修改列名
                worksheet.Cells[1, 3].Value = "分类名称"; // 修改列名
                worksheet.Cells[1, 4].Value = "供应商地址"; // 修改列名
                worksheet.Cells[1, 5].Value = "联系人"; // 修改列名
                worksheet.Cells[1, 6].Value = "联系电话"; // 修改列名
                worksheet.Cells[1, 7].Value = "邮箱"; // 修改列名
                worksheet.Cells[1, 8].Value = "备注"; // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 6]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Code;
                    worksheet.Cells[i + 2, 2].Value = list[i].Name;
                    worksheet.Cells[i + 2, 3].Value = list[i].TypeName;
                    worksheet.Cells[i + 2, 4].Value = list[i].AddrDetail;
                    worksheet.Cells[i + 2, 5].Value = list[i].Contact;
                    worksheet.Cells[i + 2, 6].Value = list[i].ContactMobile;
                    worksheet.Cells[i + 2, 7].Value = list[i].Email;
                    worksheet.Cells[i + 2, 8].Value = list[i].Remark;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 6; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 装备编号编码导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EquipmentBasicDown(List<EquipmentBasicDown> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "装备编号名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备编号编码";   // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 2]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Code;
                    worksheet.Cells[i + 2, 2].Value = list[i].Name;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 2; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 装备编号信息导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EquipmentBasicMsgDown(List<EquipmentBasicMsgDown> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备编码";   // 修改列名
                worksheet.Cells[1, 3].Value = "型号名称";   // 修改列名
                worksheet.Cells[1, 4].Value = "规格型号";   // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Code;
                    worksheet.Cells[i + 2, 2].Value = list[i].Name;
                    worksheet.Cells[i + 2, 3].Value = list[i].ModelName;
                    worksheet.Cells[i + 2, 4].Value = list[i].SpecificationModel;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion


        /// <summary>
        /// 网络地址导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult NetworkAddressDown(List<NetworkAddress> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "网络地址";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 1]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].NetAddress;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 1; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 装备维修明细导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult RepairApplicationDown(List<RepairApplication> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "维修内容";  // 修改列名
                worksheet.Cells[1, 3].Value = "维修时间";  // 修改列名
                worksheet.Cells[1, 4].Value = "维修人";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Name;
                    worksheet.Cells[i + 2, 2].Value = list[i].RepairContent;
                    if (list[i].RepairTime is DateTime repairTime)
                    {
                        worksheet.Cells[i + 2, 3].Value = repairTime;
                        worksheet.Cells[i + 2, 3].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 3].Value = list[i].RepairTime.ToString();
                    }
                    worksheet.Cells[i + 2, 4].Value = list[i].RepairUser;
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 装备领取记录导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EquipmentReceiveDown(List<EquipmentCollection> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备种类";  // 修改列名
                worksheet.Cells[1, 3].Value = "领取时间";  // 修改列名
                worksheet.Cells[1, 4].Value = "领取人";  // 修改列名
                worksheet.Cells[1, 5].Value = "归还时间";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 5]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Name;
                    worksheet.Cells[i + 2, 2].Value = list[i].EquipmentType;
                    if (list[i].CollectionDate is DateTime repairTime)
                    {
                        worksheet.Cells[i + 2, 3].Value = repairTime;
                        worksheet.Cells[i + 2, 3].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 3].Value = list[i].CollectionDate.ToString();
                    }
                    worksheet.Cells[i + 2, 4].Value = list[i].CollectionUser;
                    if (list[i].ReturnDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 5].Value = repairTime2;
                        worksheet.Cells[i + 2, 5].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 5].Value = list[i].ReturnDate.ToString();
                    }
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 5; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// 装备盘点导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult StocktakingDown(List<StocktakingOrder> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "盘点单号";  // 修改列名
                worksheet.Cells[1, 2].Value = "库房";  // 修改列名
                worksheet.Cells[1, 3].Value = "订单状态";  // 修改列名
                worksheet.Cells[1, 4].Value = "创建时间";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].OrderSn;
                    worksheet.Cells[i + 2, 2].Value = list[i].WarehouseName;
                    worksheet.Cells[i + 2, 3].Value = list[i].Status;

                    if (list[i].CreateDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 4].Value = repairTime2;
                        worksheet.Cells[i + 2, 4].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 4].Value = list[i].CreateDate.ToString();
                    }
                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// 保修工单信息管理导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EquipmentBadDown(List<EquipmentBad> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）
                worksheet.Cells[1, 1].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备编码";  // 修改列名
                worksheet.Cells[1, 3].Value = "报废原因";  // 修改列名
                worksheet.Cells[1, 4].Value = "处理人姓名";  // 修改列名
                worksheet.Cells[1, 5].Value = "审批状态";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 5]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].MaterialName;
                    worksheet.Cells[i + 2, 2].Value = list[i].MaterialCode;
                    worksheet.Cells[i + 2, 3].Value = list[i].Reason;
                    worksheet.Cells[i + 2, 4].Value = list[i].ChuLiRName;
                    worksheet.Cells[i + 2, 5].Value = list[i].Status;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 5; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 报销工单数据统计导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EquipmentBadMsgDown(List<EquipmentBad> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "报废装备编码";  // 修改列名
                worksheet.Cells[1, 2].Value = "报废装备名称";  // 修改列名
                worksheet.Cells[1, 3].Value = "数量";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 3]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].MaterialCode;
                    worksheet.Cells[i + 2, 2].Value = list[i].MaterialName;
                    worksheet.Cells[i + 2, 3].Value = list.Count();


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 3; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }



        /// <summary>
        /// 盘点信息管理导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult StocktakingMsgDown(List<StocktakingOrder> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "盘点单号";  // 修改列名
                worksheet.Cells[1, 2].Value = "库房";  // 修改列名
                worksheet.Cells[1, 3].Value = "订单状态";  // 修改列名
                worksheet.Cells[1, 4].Value = "创建时间";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].OrderSn;
                    worksheet.Cells[i + 2, 2].Value = list[i].WarehouseName;
                    worksheet.Cells[i + 2, 3].Value = list[i].Status;
                    if (list[i].CreateDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 4].Value = repairTime2;
                        worksheet.Cells[i + 2, 4].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 4].Value = list[i].CreateDate.ToString();
                    }


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 3; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }



        /// <summary>
        /// 出入库报表导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult InventoryMsgDown(List<InventoryLog> list, int type)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置边框线
                var lastRow = list.Count + 1;// 获取最后一行
                var lastColumn = 0; // 总共有4列

                // 设置自定义字段名（列名）
                if (type == 1)
                {
                    worksheet.Cells[1, 1].Value = "物资代码";  // 修改列名
                    worksheet.Cells[1, 2].Value = "物资描述";  // 修改列名
                    worksheet.Cells[1, 3].Value = "库存数量";  // 修改列名
                    worksheet.Cells[1, 4].Value = "入库数量";  // 修改列名
                    worksheet.Cells[1, 5].Value = "结余数量";  // 修改列名
                    worksheet.Cells[1, 6].Value = "入库时间";  // 修改列名
                    worksheet.Cells[1, 7].Value = "计量单位";  // 修改列名

                    using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                    {
                        headerRange.Style.Font.Bold = true; // 设置加粗
                        headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                        headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                        headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                    }

                    for (int i = 0; i < list.Count; i++)
                    {
                        worksheet.Cells[i + 2, 1].Value = list[i].MaterialCode;
                        worksheet.Cells[i + 2, 2].Value = list[i].MaterialName;
                        worksheet.Cells[i + 2, 3].Value = list[i].StartQty;
                        worksheet.Cells[i + 2, 4].Value = list[i].ChangeQty;
                        worksheet.Cells[i + 2, 5].Value = list[i].EndQty;

                        if (list[i].CreateDate is DateTime repairTime2)
                        {
                            worksheet.Cells[i + 2, 6].Value = repairTime2;
                            worksheet.Cells[i + 2, 6].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                        }
                        else
                        {
                            worksheet.Cells[i + 2, 6].Value = list[i].CreateDate.ToString();
                        }
                        worksheet.Cells[i + 2, 7].Value = list[i].BaseUnitName;

                    }
                    lastColumn = 7;
                }
                else
                {
                    worksheet.Cells[1, 1].Value = "物资代码";  // 修改列名
                    worksheet.Cells[1, 2].Value = "物资描述";  // 修改列名
                    worksheet.Cells[1, 3].Value = "物资号";  // 修改列名
                    worksheet.Cells[1, 4].Value = "基本单位";  // 修改列名
                    worksheet.Cells[1, 5].Value = "库存数量";  // 修改列名
                    worksheet.Cells[1, 6].Value = "出库数量";  // 修改列名
                    worksheet.Cells[1, 7].Value = "结余数量";  // 修改列名
                    worksheet.Cells[1, 8].Value = "库房";  // 修改列名

                    using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                    {
                        headerRange.Style.Font.Bold = true; // 设置加粗
                        headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                        headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                        headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                    }

                    for (int i = 0; i < list.Count; i++)
                    {
                        worksheet.Cells[i + 2, 1].Value = list[i].MaterialCode;
                        worksheet.Cells[i + 2, 2].Value = list[i].MaterialName;
                        worksheet.Cells[i + 2, 3].Value = list[i].MaterialCode;
                        worksheet.Cells[i + 2, 4].Value = list[i].BaseUnitName;
                        worksheet.Cells[i + 2, 5].Value = list[i].StartQty;
                        worksheet.Cells[i + 2, 6].Value = list[i].ChangeQty;
                        worksheet.Cells[i + 2, 7].Value = list[i].EndQty;
                        worksheet.Cells[i + 2, 8].Value = list[i].WarehouseName;
                     

                    }
                    lastColumn = 8;
                }




                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// 库存结余导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult StocktakeResultDown(List<StocktakeResultRecord> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "盘点单号";  // 修改列名
                worksheet.Cells[1, 2].Value = "库房";  // 修改列名
                worksheet.Cells[1, 3].Value = "货位";  // 修改列名
                worksheet.Cells[1, 4].Value = "物资名称";  // 修改列名
                worksheet.Cells[1, 5].Value = "应盘数量";  // 修改列名
                worksheet.Cells[1, 6].Value = "盘点数量";  // 修改列名
                worksheet.Cells[1, 7].Value = "盘点结果";  // 修改列名
                worksheet.Cells[1, 8].Value = "创建时间";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 8]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].OrderSn;
                    worksheet.Cells[i + 2, 2].Value = list[i].WarehouseName;
                    worksheet.Cells[i + 2, 3].Value = list[i].CellCode;
                    worksheet.Cells[i + 2, 4].Value = list[i].MaterialName;
                    worksheet.Cells[i + 2, 5].Value = list[i].OriginalQty;
                    worksheet.Cells[i + 2, 6].Value = list[i].CountQty;
                    if (list[i].Status == 1)
                    {
                        worksheet.Cells[i + 2, 7].Value = "盘盈";

                    }else if (list[i].Status == 2)
                    {
                        worksheet.Cells[i + 2, 7].Value = "盘平";
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 7].Value = "盘亏";
                    }
                    if (list[i].CreateDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 8].Value = repairTime2;
                        worksheet.Cells[i + 2, 8].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 8].Value = list[i].CreateDate.ToString();
                    }


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 8; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 库存快照导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult InventoryStockDown(List<Inventory> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "日期";  // 修改列名
                worksheet.Cells[1, 2].Value = "物资描述";  // 修改列名
                worksheet.Cells[1, 3].Value = "总数量";  // 修改列名
                worksheet.Cells[1, 4].Value = "创建时间";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].CreateDate is DateTime repairTime)
                    {
                        worksheet.Cells[i + 2, 1].Value = repairTime;
                        worksheet.Cells[i + 2, 1].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 1].Value = list[i].CreateDate.ToString();
                    }

                    worksheet.Cells[i + 2, 2].Value = list[i].MaterialName;
                    worksheet.Cells[i + 2, 3].Value = list[i].AvailableQty;

                    if (list[i].CreateDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 4].Value = repairTime2;
                        worksheet.Cells[i + 2, 4].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 4].Value = list[i].CreateDate.ToString();
                    }


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 采购计划导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult PurchaseStandardDown(List<PurchaseStandard> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "采购计划名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "适用人员数量";  // 修改列名
                worksheet.Cells[1, 3].Value = "标准描述";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 4]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].StandardName;
                    worksheet.Cells[i + 2, 2].Value = list[i].EmployeeCount;
                    worksheet.Cells[i + 2, 3].Value = list[i].Description;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 4; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 趋势统计导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult TrendDown(List<Material> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "装备编码";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 3].Value = "型号规格";  // 修改列名
                worksheet.Cells[1, 4].Value = "装备类型";  // 修改列名
                worksheet.Cells[1, 5].Value = "基本单位";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 5]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Code;
                    worksheet.Cells[i + 2, 2].Value = list[i].MaterialCategoryName;
                    worksheet.Cells[i + 2, 3].Value = list[i].ModelSpec;
                    worksheet.Cells[i + 2, 4].Value = list[i].TypeCode;
                    worksheet.Cells[i + 2, 5].Value = list[i].UnitName;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 5; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// 趋势统计导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult PurchaseOrderDown(List<EquipmentBasic> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "装备编码";  // 修改列名
                worksheet.Cells[1, 2].Value = "装备名称";  // 修改列名
                worksheet.Cells[1, 3].Value = "型号规格";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 3]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Name;
                    worksheet.Cells[i + 2, 2].Value = list[i].ModelName;
                    worksheet.Cells[i + 2, 3].Value = list[i].SpecificationModel;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 3; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 竞价信息导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult BiddingMsgDown(List<BidAnnouncement> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "竞价名称";  // 修改列名
                worksheet.Cells[1, 2].Value = "竞价开始时间";  // 修改列名
                worksheet.Cells[1, 3].Value = "竞价结束时间";  // 修改列名
                worksheet.Cells[1, 4].Value = "采购内容描述";  // 修改列名
                worksheet.Cells[1, 5].Value = "金额限制";  // 修改列名
                worksheet.Cells[1, 6].Value = "审核状态";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 6]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].Name;

                    if (list[i].StartTime is DateTime repairTime)
                    {
                        worksheet.Cells[i + 2, 2].Value = repairTime;
                        worksheet.Cells[i + 2, 2].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 2].Value = list[i].StartTime.ToString();
                    }

                    if (list[i].EndTime is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 3].Value = repairTime2;
                        worksheet.Cells[i + 2, 3].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 3].Value = list[i].EndTime.ToString();
                    }

                    worksheet.Cells[i + 2, 4].Value = list[i].Description;
                    worksheet.Cells[i + 2, 5].Value = list[i].AmountLimit;
                    worksheet.Cells[i + 2, 6].Value = list[i].Status;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 6; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }

        /// <summary>
        /// 供应商对账明细导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult SuppliersDetailDown(List<SupplierTransaction> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "供应商";  // 修改列名
                worksheet.Cells[1, 2].Value = "类型";  // 修改列名
                worksheet.Cells[1, 3].Value = "日期";  // 修改列名
                worksheet.Cells[1, 4].Value = "详细描述";  // 修改列名
                worksheet.Cells[1, 5].Value = "金额";  // 修改列名
                worksheet.Cells[1, 6].Value = "设备信息";  // 修改列名
                worksheet.Cells[1, 7].Value = "是否有发票";  // 修改列名
                worksheet.Cells[1, 8].Value = "结果";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 8]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].SupplierID;
                    worksheet.Cells[i + 2, 2].Value = list[i].TransactionType;
                    if (list[i].TransactionDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 3].Value = repairTime2;
                        worksheet.Cells[i + 2, 3].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 3].Value = list[i].TransactionDate.ToString();
                    }

                    worksheet.Cells[i + 2, 4].Value = list[i].Details;
                    worksheet.Cells[i + 2, 5].Value = list[i].Amount;
                    worksheet.Cells[i + 2, 6].Value = list[i].EquipmentInfo;
                    worksheet.Cells[i + 2, 7].Value = list[i].InvoiceInfo;
                    worksheet.Cells[i + 2, 8].Value = list[i].TransactionOutcome;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 8; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }


        /// <summary>
        /// 供应商对账明细导出
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        protected internal IActionResult EMPDown(List<EMPModel> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            //memoryStream.SaveAs(list);
            //memoryStream.Seek(0, SeekOrigin.Begin);

            // 使用 EPPlus 创建 Excel 文件
            using (var package = new ExcelPackage(memoryStream))
            {
                // 创建工作表
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置自定义字段名（列名）

                worksheet.Cells[1, 1].Value = "付款单号";  // 修改列名
                worksheet.Cells[1, 2].Value = "付款方式";  // 修改列名
                worksheet.Cells[1, 3].Value = "付款日期";  // 修改列名
                worksheet.Cells[1, 4].Value = "付款金额";  // 修改列名
                worksheet.Cells[1, 5].Value = "付款对象";  // 修改列名
                worksheet.Cells[1, 6].Value = "付款原因";  // 修改列名
                worksheet.Cells[1, 7].Value = "合同号";  // 修改列名
                worksheet.Cells[1, 8].Value = "发票号码";  // 修改列名
                worksheet.Cells[1, 9].Value = "付款确认人";  // 修改列名

                using (var headerRange = worksheet.Cells[1, 1, 1, 9]) // 标题范围
                {
                    headerRange.Style.Font.Bold = true; // 设置加粗
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid; // 填充背景色
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); // 设置背景色为浅灰色
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // 设置居中对齐
                }

                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].PaymentID;
                    worksheet.Cells[i + 2, 2].Value = list[i].PaymentMethod;
                    if (list[i].PaymentDate is DateTime repairTime2)
                    {
                        worksheet.Cells[i + 2, 3].Value = repairTime2;
                        worksheet.Cells[i + 2, 3].Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";  // 设置日期时间格式
                    }
                    else
                    {
                        worksheet.Cells[i + 2, 3].Value = list[i].PaymentDate.ToString();
                    }

                    worksheet.Cells[i + 2, 4].Value = list[i].Amount;
                    worksheet.Cells[i + 2, 5].Value = list[i].PayeeName;
                    worksheet.Cells[i + 2, 6].Value = list[i].PaymentDescription;
                    worksheet.Cells[i + 2, 7].Value = list[i].ContractNumber;
                    worksheet.Cells[i + 2, 8].Value = list[i].InvoiceNumber;
                    worksheet.Cells[i + 2, 9].Value = list[i].Approver;


                }

                // 设置边框线
                var lastRow = list.Count + 1; // 获取最后一行
                var lastColumn = 9; // 总共有4列

                // 设置所有单元格的边框
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存文件到 memoryStream
                package.Save();
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }





        #region  供应商应付账单类导出
        protected internal IActionResult InvDownVendorTransaction(List<VendorTransaction> list)
        {
            ExcelPackage.LicenseContext = LicenseContext.Commercial;

            var memoryStream = new MemoryStream();

            using (var package = new ExcelPackage(memoryStream))
            {
                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                // 设置表头
                worksheet.Cells[1, 1].Value = "供应商ID";
                worksheet.Cells[1, 2].Value = "供应商名称";
                worksheet.Cells[1, 3].Value = "联系人";
                worksheet.Cells[1, 4].Value = "联系电话";
                worksheet.Cells[1, 5].Value = "联系邮箱";
                worksheet.Cells[1, 6].Value = "地址";
                worksheet.Cells[1, 7].Value = "商品名称";
                worksheet.Cells[1, 8].Value = "单价";
                worksheet.Cells[1, 9].Value = "数量";
                worksheet.Cells[1, 10].Value = "总金额";
                worksheet.Cells[1, 11].Value = "账单日期";
                worksheet.Cells[1, 12].Value = "账单金额";
                worksheet.Cells[1, 13].Value = "已支付金额";
                worksheet.Cells[1, 14].Value = "应付金额";




                // 设置表头样式
                using (var headerRange = worksheet.Cells[1, 1, 1, 14])
                {
                    headerRange.Style.Font.Bold = true;
                    headerRange.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    headerRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    headerRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                // 填充数据
                for (int i = 0; i < list.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = list[i].VendorId;
                    worksheet.Cells[i + 2, 2].Value = list[i].VendorName;
                    worksheet.Cells[i + 2, 3].Value = list[i].ContactPerson;
                    worksheet.Cells[i + 2, 4].Value = list[i].PhoneNumber;
                    worksheet.Cells[i + 2, 5].Value = list[i].Email;
                    worksheet.Cells[i + 2, 6].Value = list[i].Address;
                    worksheet.Cells[i + 2, 7].Value = list[i].ItemName;
                    worksheet.Cells[i + 2, 8].Value = list[i].UnitPrice;
                    worksheet.Cells[i + 2, 9].Value = list[i].Quantity;
                    worksheet.Cells[i + 2, 10].Value = list[i].TotalAmount;
                    worksheet.Cells[i + 2, 11].Value = list[i].InvoiceDate.ToString("yyyy-MM-dd");
                    worksheet.Cells[i + 2, 12].Value = list[i].InvoiceAmount;
                    worksheet.Cells[i + 2, 13].Value = list[i].PaidAmount;
                    worksheet.Cells[i + 2, 14].Value = list[i].DueAmount;

                }

                // 动态调整列宽
                worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();

                // 获取最后一行和列
                var lastRow = list.Count + 1;
                var lastColumn = 14; // 最后一列的列号

                // 设置边框样式
                var range = worksheet.Cells[1, 1, lastRow, lastColumn];
                range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
                range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                // 保存到内存流
                package.Save();
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = $"{Guid.NewGuid()}.xlsx"
            };
        }
        #endregion

    }
}
